package com.EAIPClub.userdatamanager.controller;

import com.EAIPClub.userdatamanager.service.UserDataService;
import com.api.POJO.UserDataManager.Data.User;
import com.api.POJO.UserDataManager.Data.UserGroup;
import com.api.POJO.UserDataManager.Data.UserPrivileges;
import com.api.POJO.UserDataManager.UserData;
import com.api.POJO.UserDataManager.Result.UserDataReturnMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description :用户数据管理模块接口
 * @Author :崔昌赫
 * @Date : 2021/10/10
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class UserDataController {
    private UserDataService userDataService;

    @Autowired
    public void setUserDataService(UserDataService userDataService) {
        this.userDataService = userDataService;
    }

    @GetMapping("/get/info/uid/{uid}")
    UserDataReturnMsg findUserAllInfoByUid(@PathVariable String uid){
        log.info("接受到数据:\nuid:{}",uid);
        return userDataService.findUserAllInfoByUid(uid);
    }
    @GetMapping("/get/info/email/{email}")
    UserDataReturnMsg findUserAllInfoByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.findUserAllInfoByEmail(email);
    }

    @GetMapping("/get/info/base/uid/{uid}")
    UserDataReturnMsg findUserBaseInfoByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.findUserBaseInfoByUid(uid);
    }
    @GetMapping("/get/info/base/email/{email}")
    UserDataReturnMsg findUserBaseInfoByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.findUserBaseInfoByEmail(email);
    }
    @GetMapping("/get/privileges/uid/{uid}")
    UserDataReturnMsg findUserPrivilegesByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.findUserPrivilegesByUid(uid);
    }
    @GetMapping("/get/privileges/email/{email}")
    UserDataReturnMsg findUserPrivilegesByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.findUserPrivilegesByEmail(email);
    }

    @GetMapping("/get/group/uid/{uid}")
    UserDataReturnMsg findUserGroupByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.findUserGroupByUid(uid);
    }
    @GetMapping("/get/group/email/{email}")
    UserDataReturnMsg findUserGroupByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.findUserGroupByEmail(email);
    }

    @PutMapping("/update/info/uid/{uid}")
    UserDataReturnMsg updateUserAllInfoByUid(@PathVariable String uid, @RequestBody UserData userData){
        log.info("接收到数据:\nuid:{}\nuserData:{}",uid,userData);
        return userDataService.updateUserAllInfoByUid(uid, userData.getUser(), userData.getUserPrivileges(), userData.getUserGroup());
    }
    @PutMapping("/update/info/email/{email}")
    UserDataReturnMsg updateUserAllInfoByEmail(@PathVariable String email, @RequestBody UserData userData){
        log.info("接收到数据:\nemail:{}\nuserData:{}",email,userData);
        return userDataService.updateUserAllInfoByEmail(email, userData.getUser(), userData.getUserPrivileges(), userData.getUserGroup());
    }

    @PutMapping("/update/info/base/uid/{uid}")
    UserDataReturnMsg updateUserBaseInfoByUid(@PathVariable String uid, @RequestBody User user){
        log.info("接收到数据:\nuid:{}\nuser:{}",uid,user);
        return userDataService.updateUserBaseInfoByUid(uid, user);
    }
    @PutMapping("/update/info/base/email/{email}")
    UserDataReturnMsg updateUserBaseInfoByEmail(@PathVariable String email, @RequestBody User user){
        log.info("接收到数据:\nemail:{}\nuser:{}",email,user);
        return userDataService.updateUserBaseInfoByEmail(email, user);
    }

    @PutMapping("/update/privileges/uid/{uid}")
    UserDataReturnMsg updateUserPrivilegesByUid(@PathVariable String uid, @RequestBody UserPrivileges userPrivileges){
        log.info("接收到数据:\nuid:{}\nuserPrivileges:{}",uid,userPrivileges);
        return userDataService.updateUserPrivilegesByUid(uid, userPrivileges);
    }
    @PutMapping("/update/privileges/email/{email}")
    UserDataReturnMsg updateUserPrivilegesByEmail(@PathVariable String email, @RequestBody UserPrivileges userPrivileges){
        log.info("接收到数据:\nemail:{}\nuserPrivileges:{}",email,userPrivileges);
        return userDataService.updateUserPrivilegesByEmail(email, userPrivileges);
    }

    @PutMapping("/update/group/uid/{uid}")
    UserDataReturnMsg updateUserGroupByUid(@PathVariable String uid, @RequestBody UserGroup userGroup){
        log.info("接收到数据:\nuid:{}\nuserGroup:{}",uid,userGroup);
        return userDataService.updateUserGroupByUid(uid, userGroup);
    }
    @PutMapping("/update/group/email/{email}")
    UserDataReturnMsg updateUserGroupByEmail(@PathVariable String email, @RequestBody UserGroup userGroup){
        log.info("接收到数据:\nemail:{}\nuserGroup:{}",email,userGroup);
        return userDataService.updateUserGroupByEmail(email, userGroup);
    }

    @PostMapping("/add/info")
    UserDataReturnMsg addUserAllInfo(@RequestBody UserData userData){
        log.info("接收到数据:\nuserData:{}",userData);
        return userDataService.addUserAllInfo(userData.getUser(), userData.getUserPrivileges(), userData.getUserGroup());
    }

    @PostMapping("/add/info/base")
    UserDataReturnMsg addUserBaseInfo(@RequestBody User user){
        log.info("接收到数据:\nuser:{}",user);
        return userDataService.addUserBaseInfo(user);
    }

    @PostMapping("/add/privileges")
    UserDataReturnMsg addUserPrivileges(@RequestBody UserPrivileges userPrivileges){
        log.info("接收到数据:\nuserPrivileges:{}",userPrivileges);
        return userDataService.addUserPrivileges(userPrivileges);
    }

    @PostMapping("/add/group")
    UserDataReturnMsg addUserGroup(@RequestBody UserGroup userGroup){
        log.info("接收到数据:\nuserGroup:{}",userGroup);
        return userDataService.addUserGroup(userGroup);
    }

    @DeleteMapping("/delete/info/uid/{uid}")
    UserDataReturnMsg deleteUserAllInfoByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.deleteUserAllInfoByUid(uid);
    }
    @DeleteMapping("/delete/info/email/{email}")
    UserDataReturnMsg deleteUserAllInfoByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.deleteUserAllInfoByEmail(email);
    }

    @DeleteMapping("/delete/info/base/uid/{uid}")
    UserDataReturnMsg deleteUserBaseInfoByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.deleteUserBaseInfoByUid(uid);
    }
    @DeleteMapping("/delete/info/base/email/{email}")
    UserDataReturnMsg deleteUserBaseInfoByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.deleteUserBaseInfoByEmail(email);
    }

    @DeleteMapping("/delete/privileges/uid/{uid}")
    UserDataReturnMsg deleteUserPrivilegesByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.deleteUserPrivilegesByUid(uid);
    }
    @DeleteMapping("/delete/privileges/email/{email}")
    UserDataReturnMsg deleteUserPrivilegesByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.deleteUserPrivilegesByEmail(email);
    }

    @DeleteMapping("/delete/group/uid/{uid}")
    UserDataReturnMsg deleteUserGroupByUid(@PathVariable String uid){
        log.info("接收到数据:\nuid:{}",uid);
        return userDataService.deleteUserGroupByUid(uid);
    }
    @DeleteMapping("/delete/group/email/{email}")
    UserDataReturnMsg deleteUserGroupByEmail(@PathVariable String email){
        log.info("接收到数据:\nemail:{}",email);
        return userDataService.deleteUserGroupByEmail(email);
    }

}
